home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tagsgen.exe / ASMTAG.E < prev    next >
Text File  |  1992-03-29  |  26KB  |  776 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: asmtag.c
  5.    Author: J. Kercheval
  6.    Created: Sun, 07/14/1991  17:25:26
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Sun, 07/14/1991  20:25:59  creation
  12.    J. Kercheval  Mon, 07/15/1991  22:47:30  finish finite state machine parser
  13.    J. Kercheval  Wed, 07/17/1991  21:35:43  add IsMember() and get_token()
  14.    J. Kercheval  Thu, 07/18/1991  19:57:34  add flags checking
  15.    J. Kercheval  Sun, 07/21/1991  15:58:56  add comment block support
  16.    J. Kercheval  Sat, 07/27/1991  21:16:53  remove public post process support
  17.    J. Kercheval  Sat, 07/27/1991  22:50:49  performance considerations (+10%)
  18.    J. Kercheval  Sat, 08/10/1991  18:14:46  Speed up IsMember()
  19.    J. Kercheval  Fri, 09/13/1991  01:17:05  add when_loading() to remap def_srch_case_map[]
  20.    J. Kercheval  Thu, 10/03/1991  12:27:37  fix logic outputting local labels
  21.    J. Kercheval  Sat, 10/05/1991  14:06:33  add ASMTagWant defines
  22. */
  23.  
  24. /*
  25.  * This file implements tagging for .ASM and .INC files which contain 80x86
  26.  * assembler in the MASM/TASM syntax.  This file defines no new commands and
  27.  * is intended to work with the tags package included with V5.0 of Epsilon.
  28.  * There is no problem using modified tags packages providing calls are made
  29.  * to tags_suffix_???() routines in the same way Epsilon does this and that
  30.  * an output routine add_tag() is used.  All that should be required is to
  31.  * compile and load this file and this module will be used transparently to
  32.  * you.
  33.  *
  34.  * This module implements tagging for UNION, STRUC, MACRO, PROC, LABEL
  35.  * keywords as well as for implicit labels (label:) and for data defintions
  36.  * (ie. equ, =, dq, dw, db, etc....).  The performance cost on a per tag
  37.  * basis is negligable, but since more tagging is done, you should expect a
  38.  * practical 10%-20% performance hit on a per file basis.  This tagger is not
  39.  * intended to do all of your work for you but is designed to be used in
  40.  * conjunction with the tags generator I have developed and is now available.
  41.  * This file implements the same semantic parser as is found in that
  42.  * executable.  Use the executable in your make file for very fast and
  43.  * updated tags.  If you have problems finding it, contact me and I can point
  44.  * the way...
  45.  *
  46.  * There is defined at the end of this module a when_loading() function which
  47.  * alters the default search case map to allow *correct* (or at least
  48.  * consistent sorting with sort routines external to Epsilon.  In particular,
  49.  * to produce the same sort order as any UNIX, VMS or HP style sort or with
  50.  * the tags generator this module is supposed to coexist with this mapping
  51.  * must be done.  You should see no difference in the location of sorted
  52.  * buffers except for lines starting with ^, [, \, ] and _.
  53.  *
  54.  * This code is dedicated to the public domain with the caveat that Lugaru is
  55.  * welcome to use this within their distribution source code which is
  56.  * supplied with Epsilon.
  57.  *
  58.  * Good Tagging,
  59.  *
  60.  *      jbk@wrq.com
  61.  *
  62.  *      John Kercheval
  63.  *      127 NW Bowdoin Pl #105
  64.  *      Seattle, WA  98107-4960
  65.  *      August 10, 1991
  66.  */
  67.  
  68. #include <eel.h>
  69.  
  70. #ifndef BOOLEAN
  71. #define BOOLEAN int
  72. #define TRUE 1
  73. #define FALSE 0
  74. #endif
  75.  
  76. /* This is a list of the types of tokens you may want to tag.  Set them true
  77.  * if you want that particular type of tag. 
  78.  */
  79. #define ASMTagWantProc TRUE
  80. #define ASMTagWantMacro TRUE
  81. #define ASMTagWantLabel TRUE
  82. #define ASMTagWantStruc TRUE
  83. #define ASMTagWantUnion TRUE
  84. #define ASMTagWantDefine TRUE
  85.  
  86. /*
  87.  * The finite state machine allows the following interesting paths
  88.  *
  89.  *    1 - Discard, Parse1, Symbol1
  90.  *    2 - Discard, Parse1, Parse2, Symbol2
  91.  *    3 - Discard, Parse1, Parse2, Define
  92.  *
  93.  * all the important cases follow one of these paths according to MASM/TASM
  94.  * syntax.  The exit state is for finish up routine calls and some paths not
  95.  * covered here are simple error paths and probably result from syntax errors
  96.  *
  97.  *  enum state { Discard, Parse1, Parse2, Symbol1, Symbol2, Define, Exit };
  98.  */
  99. /*
  100.  * emulate an enumerated type for the state machine
  101.  */
  102.  
  103. #define Discard 0
  104. #define Parse1  1
  105. #define Parse2  2
  106. #define Symbol1 3
  107. #define Symbol2 4
  108. #define Define  5
  109. #define Exit    6
  110.  
  111. typedef int State;
  112.  
  113. #define COMMENT_CHAR ';'
  114.  
  115. #define SYMBOL_SIZE 15
  116.  
  117.  
  118. /*----------------------------------------------------------------------------
  119.  *
  120.  * The symbol lists represent all the symbols we are interested in either
  121.  * obtaining or ignoring.  The first element of each of these symbol lists is
  122.  * a string containing all the first characters within the symbol list.  This
  123.  * allows faster rejection for IsMember() which is called often.
  124.  *
  125.  ---------------------------------------------------------------------------*/
  126.  
  127. /* symbols which are not significant for this parser */
  128. char ASM_NOP_Sym[][SYMBOL_SIZE] =
  129. {
  130.     "cpbfnwo",                  /* list of starting characters of symbols
  131.                                  * below */
  132.     "c",                        /* C language declaration */
  133.     "pascal",                   /* PASCAL language declaration */
  134.     "basic",                    /* BASIC language declaration */
  135.     "fortran",                  /* FORTRAN language declaration */
  136.     "prolog",                   /* PROLOG language declaration */
  137.     "nolanguage",               /* generic language declaration */
  138.     "windows",                  /* WINDOWS exit and entry modifier */
  139.     "oddnear",                  /* overlay modifier */
  140.     "oddfar",                   /* overlay modifier */
  141.     "normal",                   /* normal procedure entry/exit code */
  142.     "\0"
  143. };
  144.  
  145. /* symbols which begin a comment block */
  146. char ASM_comment_block[][SYMBOL_SIZE] =
  147. {
  148.     "c",                        /* list of starting characters of symbols
  149.                                  * below */
  150.     "comment",                  /* begin comment block, next character is
  151.                                  * delimiter */
  152.     "\0"
  153. };
  154.  
  155.  
  156. /* create the function for determining if a character is a delimiter */
  157. #define IsDelim(c) ( _ASM_delim_table[c] )
  158.  
  159. /* the indexed table for white space character lookup */
  160. BOOLEAN _ASM_delim_table[256];
  161.  
  162. /* valid delimiters for this syntax */
  163. char ASM_delim[] = " \t\n;:=.,\"()<>[]*-+/";
  164.  
  165.  
  166. /* create the function for determining if a character is a whitespace */
  167. #define IsWhite(c) ( _ASM_white_table[c] )
  168.  
  169. /* the indexed table for white space character lookup */
  170. BOOLEAN _ASM_white_table[256];
  171.  
  172. /* whitespace characters */
  173. char ASM_white[] = " \t\v\f";
  174.  
  175.  
  176. /* symbols which both are delimiters and a special token, these are
  177.     special tokens only when found at the the beginning of a string of
  178.     1 or more delimiters */
  179. char ASM_delim_Sym[] = "=:";
  180.  
  181. /* symbols which fit into the Define state and represent a tagged symbol */
  182. /* state Define depends on the token ":" being at index 1 in this list */
  183. char ASM_def[][SYMBOL_SIZE] =
  184. {
  185.     ":e=cd",                    /* list of starting characters of symbols
  186.                                  * below */
  187.     ":",                        /* local labels */
  188.     "equ",                      /* equivalence */
  189.     "=",                        /* equivalence */
  190.     "catstr",                   /* concatenated and named strings */
  191.     "db",                       /* named byte data definition */
  192.     "dw",                       /* named word data definition */
  193.     "dd",                       /* named double word data definition */
  194.     "dp",                       /* named 6 byte far pointer data area
  195.                                  * definition */
  196.     "df",                       /* named 6 byte far pointer definition */
  197.     "dq",                       /* named quad word data definition */
  198.     "dt",                       /* named 10 byte data area */
  199.     "\0"
  200. };
  201.  
  202. /* symbols which fit into the Symbol state and represent a tagged symbol */
  203. char ASM_sym[][SYMBOL_SIZE] =
  204. {
  205.     "pmlsu",                    /* list of starting character of symbols
  206.                                  * below */
  207.     "proc",                     /* proced